package indi.readbook.example.common.res;

import io.swagger.annotations.ApiModelProperty;

public class ViewResult<T> {

    @ApiModelProperty(value = "错误代码 200：正常  500错误")
    private Integer code;

    @ApiModelProperty("返回说明")
    private String msg;

    @ApiModelProperty("返回数据")
    private T data;

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public ViewResult() {

    }

    public ViewResult(Integer code) {
        this.code = code;
    }

    public ViewResult(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public ViewResult(Integer code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static ViewResult success() {
        return new ViewResult(200, "成功");
    }

    public static ViewResult success(Object data) {
        return new ViewResult(200, "成功", data);
    }

    public static ViewResult success(Integer code, String msg, Object data) {
        return new ViewResult(code, msg, data);
    }

    public static ViewResult success(Integer code, String msg) {
        return new ViewResult(code, msg);
    }

    public static ViewResult noLogin() {
        ViewResult r = new ViewResult(401, "请登录后再次访问");
        return r;
    }

    public static ViewResult noLogin(String message) {
        ViewResult r = new ViewResult(401, message);
        return r;
    }

    public static ViewResult error(int code, String msg) {
        ViewResult resultData = new ViewResult(code,msg);
        return resultData;
    }

    public static ViewResult error(String msg) {
        ViewResult resultData = new ViewResult(500,msg);
        return resultData;
    }

    public static ViewResult error() {
        ViewResult resultData = new ViewResult(500,"服务器繁忙");
        return resultData;
    }
}